home *** CD-ROM | disk | FTP | other *** search
- Path: digex.net!not-for-mail
- From: jdc@access2.digex.net (John Cochran)
- Newsgroups: comp.lang.c
- Subject: Re: fast find algorithm
- Date: 10 Apr 1996 21:56:23 -0400
- Organization: Express Access Online Communications, Greenbelt, MD USA
- Message-ID: <4khos7$fk1@access2.digex.net>
- References: <Dp8wE6.8DG@cix.compulink.co.uk> <4k9ggs$4ov@news1.mnsinc.com> <4kbrg8$luu@druid.borland.com> <316B2716.4993@airmail.net>
- NNTP-Posting-Host: access2.digex.net
-
- In article <316B2716.4993@airmail.net>, Mark Nelson <markn@airmail.net> wrote:
- >Pete Becker wrote:
- >>
- >> In article <4k9ggs$4ov@news1.mnsinc.com>, huang@mnsinc.com says...
- >> >
- >> >Rogerio Brito (rbrito@ime.usp.br) wrote:
- >> >: huang@mnsinc.com (Szu-Wen Huang) wrote:
- >> >: >Falstaff (falstaff@xs4all.nl) wrote:
- >> >: >...
- >> >: >: Hashing is slightly slower than straight table lookup and can't be
- >> >: >: used when you want to delete elements from your table.
- >> >: >...
- >> >
- >> >: >Hashing can't be used when you want to delete elements? Please explain.
- >> >
- >> It depends on what you use to resolve conflicting hash values for different
- >> elements. If you resolve conflicts by rehashing, or by moving to the next
- >> available entry in the hash array, or any other mechanism that uses the array
- >> itself as the storage location for the conflicting value, then you can't delete
- >> items, cause once you do there's no way to get to the ones that used to
- >> conflict. The first one you try will map to your now-empty location, and it'll
- >> look like it wasn't found.
- >> If you use a linked list at each array location to resolve conflicts then
- >> you can delete elements.
- >
- >Knuth gives an algorithm for deleting elements from a table when using linear probing,
- >and it's pretty easy to see how that would work. I'm not sure there is a practical
- >way to remove elements when using a secondary hash probe...
- >
- >Mark Nelson
- >http://web2.airmail.net/markn
-
- It's easy to do inserts or deletes in a hash table. What you have to do is
- have 2 flag values for a hash entry. Call them EMPTY and DELETED.
-
- To insert an item into the table.
- A. Generate hash
- B. If table[hash] EMPTY or DELETED, then insert item into current entry
- and exit
- C. Rehash and repeat step B
-
- To search for an entry in the table
- A. Generate hash
- B. If table[hash] EMPTY - return failure
- C. If table[hash] desired entry - return success
- D. Rehash and repeat step B
-
- To delete an entry
- A. Perform search for entry
- B. If not found - return
- C. If found, replace with DELETED
-
-